import React, { useEffect, useState, useReducer, useContext } from 'react';
import Sub from './sub';
import {initialState, reducer} from './store';
import {MyContext} from './provider';

export default function Counter() {
  // 返回值：最新的state和dispatch函数
  const [state, dispatch] = useReducer(reducer, initialState);
  console.log("main")
  return (
    <div>
      <MyContext.Provider value={{state: state, dispatch: dispatch}}>
        main Count: {state.count}
        <Sub></Sub>
      </MyContext.Provider>

    </div>
  );
}
